<?php
namespace App\Modules\Department;

use App\Modules\AdapterApi;
use App\Services\User\UserIndex;
/**
 * 对部门管理的操作
 */
class Department extends AdapterApi
{
    // 获取部门列表分页数据
    public function list(): array
    {
        $data = pick_array($this->postData, ['page', 'list_rows', 'status']);

        return UserIndex::Department()->list($data);
    }
    // 增加一个部门
    public function add(): array
    {
        $data = pick_array($this->postData, ['name','name_cn','weight']);

        return UserIndex::Department()->add($data);
    }
    // 获取某个部门的详情
    public function getDepartmentInfo(): array
    {
        $data = pick_array($this->postData,['id']);

        return UserIndex::Department()->getDepartmentInfo($data);
    }
    // 编辑一个部门
    public function edit(): array
    {
        $data = pick_array($this->postData,['id','name','name_cn','weight','menu']);

        return UserIndex::Department()->edit($data);
    }
    // 启用一个部门
    public function start(): array
    {
        $data = pick_array($this->postData, ['id','name']);

        return UserIndex::Department()->start($data);
    }
    // 停用一个部门
    public function stop(): array
    {
        $data = pick_array($this->postData, ['id','name']);

        return UserIndex::Department()->stop($data);
    }

    //通过权限id获取 拥有该权限的角色列表和未拥有角色列表
   public function departmentByRole(): array
   {
        $data = pick_array($this->postData, ['role_id']);
        return UserIndex::Department()->departmentByRole($data);
   }
    // 给某个部门N个角色(关系表)
    public function addRoleByDepartment(): array
    {
        $data = pick_array($this->postData,['department_id','role_ids']);
        //$data = $this->haveIssetReceiveData(['role_id'=>' ', 'auth_ids'=>'0']);
        if ($data['role_ids'] === '') {
            return \verify_err($data, 'role_ids');
        }
        return UserIndex::Department()->addRoleByDepartment($data);
    }
    // 解除某个部门的N个角色(关系表,删除)
    public function removeRoleByDepartment(): array
    {
        $data = pick_array($this->postData,['department_id','role_ids']);

       // $data = $this->haveIssetReceiveData(['role_id'=>'0', 'auth_ids'=>' ']);
        if ($data['role_ids'] === '') {
            return \verify_err($data, 'role_ids');
        }
        return UserIndex::Department()->removeRoleByDepartment($data);
    }
}